package com.santiao.fuel.ui.widget;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.santiao.fuel.R;
import com.santiao.fuel.utils.DisplayUtil;


/* loaded from: classes.dex */
public class CircleProgressView extends View {

    /* renamed from: f  reason: collision with root package name */
    public final int f6478f = DisplayUtil.dip2px(getContext(), 6.0f);

    /* renamed from: a  reason: collision with root package name */
    public Paint f6479a;

    /* renamed from: b  reason: collision with root package name */
    public Paint f6480b;

    /* renamed from: c  reason: collision with root package name */
    public RectF f6481c;

    /* renamed from: d  reason: collision with root package name */
    public long f6482d;

    /* renamed from: e  reason: collision with root package name */
    public float f6483e;

    /* loaded from: classes.dex */
    public class a extends AnimatorListenerAdapter {

        /* renamed from: a  reason: collision with root package name */
        public final c f6484a;

        public a(c cVar) {
            this.f6484a = cVar;
        }

        @Override
        // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            super.onAnimationEnd(animator);
            c cVar = this.f6484a;
            if (cVar != null) {
                cVar.a();
            }
        }
    }

    /* loaded from: classes.dex */
    public class b implements ValueAnimator.AnimatorUpdateListener {

        /* renamed from: a  reason: collision with root package name */
        public final c f6486a;

        public b(c cVar) {
            this.f6486a = cVar;
        }

        @Override // android.animation.ValueAnimator.AnimatorUpdateListener
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            CircleProgressView.this.f6483e = ((Float) valueAnimator.getAnimatedValue()).floatValue();
            float f2 = CircleProgressView.this.f6483e / 270.0f;
            c cVar = this.f6486a;
            if (cVar != null) {
                cVar.a(f2);
            }
            CircleProgressView.this.postInvalidate();
        }
    }

    /* loaded from: classes.dex */
    public interface c {
        void a();

        void a(float f2);
    }

    public CircleProgressView(Context context) {
        this(context, null);
    }

    private void a(AttributeSet attributeSet) {
        this.f6479a.setStrokeCap(Paint.Cap.ROUND);
        this.f6479a.setStrokeWidth((float) f6478f);
        this.f6479a.setColor(ContextCompat.getColor(getContext(), R.color.color1dc276));
        this.f6479a.setStyle(Paint.Style.STROKE);
        this.f6480b.setStrokeCap(Paint.Cap.ROUND);
        this.f6480b.setStrokeWidth((float) f6478f);
        this.f6480b.setColor(-3024416);
        this.f6480b.setStyle(Paint.Style.STROKE);
        float f2 = (float) ((int) ((((float) this.f6482d) / 2.097152E7f) * 270.0f));
        this.f6483e = f2;
        this.f6483e = Math.min(270.0f, f2);
    }

    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawArc(this.f6481c, 135.0f, 270.0f, false, this.f6480b);
        canvas.drawArc(this.f6481c, 135.0f, this.f6483e, false, this.f6479a);
    }

    @Override // android.view.View
    public void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        int size = MeasureSpec.getSize(i);
        setMeasuredDimension(size, size);
        a();
    }

    public void setSpeed(long j) {
        a(j, null);
    }

    public CircleProgressView(Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f6479a = new Paint(1);
        this.f6480b = new Paint(1);
        a(attributeSet);
    }

    private void a() {
        int i = f6478f / 2;
        float f2 = (float) i;
        this.f6481c = new RectF(f2, f2, (float) (getMeasuredWidth() - i), (float) (getMeasuredWidth() - i));
    }

    public void a(long j, c cVar) {
        this.f6482d = j;
        char c2 = 0;
        ValueAnimator ofFloat = ValueAnimator.ofFloat(this.f6483e, Math.min(270.0f, (((float) j) / 2.097152E7f) * 270.0f));
        int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
        if (i > 0) {
            c2 = 1;
        } else if (i != 0) {
            c2 = 65535;
        }
        ofFloat.setDuration(c2 == 0 ? 450 : 300);
        ofFloat.setInterpolator(c2 == 0 ? new AccelerateInterpolator() : new AccelerateDecelerateInterpolator());
        ofFloat.addUpdateListener(new b(cVar));
        ofFloat.addListener(new a(cVar));
        ofFloat.start();
    }
}